home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2936 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.genie.net!usenet
  2. From: i.einman@genie.com (IAN J. EINMAN)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: SAS-C and Interrupts
  5. Date: 7 Feb 1996 07:23:53 GMT
  6. Organization: via GEnie Services (1-800-638-9636 or info@genie.com)
  7. Sender: i.einman@genie.com (IAN J. EINMAN)
  8. Message-ID: <4f9k29$lt2@rock101.genie.net>
  9. NNTP-Posting-Host: rock103.is.ge.com
  10.  
  11. __interrupt __saveds IRoutine(void)
  12. {
  13.    blah blah blah++
  14. }
  15.  
  16. The __interrupt insures SAS will set the CCR on return, and disables stackchecking.
  17. Be sure that stack extension is turned off.
  18.  
  19. Finally, the __saveds is desperately needed if you try to access variables.  The
  20. C code will access your variables as an offset from A4.
  21.  
  22. For example,
  23.  
  24.    count += 5;
  25.  
  26. would become
  27.  
  28.    addq.l #5,_count(a4)
  29.  
  30. The problem is this.  Without __saveds, your program (C-code) will not have a4 set.
  31.  
  32. Imagine this
  33.  
  34. assembly code:
  35.    move.l a3,a4
  36.    lea 24(a4),a0  (just misc code)
  37.    addq.l #1,d0
  38.    jsr _interrupt(pc)
  39.    move.l d0,(a3)+
  40.    rts
  41.  
  42. C code
  43. {
  44.    count++;           addq.l #1,count(a4)
  45. }                     rts
  46.  
  47. This will crash, since A4 was tampered with in the Asm part previously.  The __saveds
  48. keyword will change the "interrupt"routine to look more like this:
  49.  
  50. C code
  51. __saveds interrupt(void)
  52. {
  53.                       move.l __saveds(pc),a4
  54.    count ++;          addq.l #1,count(a4)
  55. }                     rts
  56.  
  57.  
  58. Hope this helps.
  59.  
  60. Ian J. Einman
  61. i.einman@genie.com
  62.  
  63.